package com.lapis17.stock.controller;

import com.lapis17.stock.pojo.entity.SysUser;
import com.lapis17.stock.service.SysUserService;
import com.lapis17.stock.vo.req.LoginReqVo;
import com.lapis17.stock.vo.resp.LoginRespVo;
import com.lapis17.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(description = "用户相关接口")
@RestController
@RequestMapping("/api")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;


    @ApiOperation("根据用户名查询")
    @RequestMapping("/user/{username}")
    @ApiImplicitParam(name = "username", value = "用户名", type = "path", dataType = "string")
    public SysUser findByUsername(@PathVariable("username") String username) {
        SysUser User = sysUserService.findByUsername(username);
        return User;
    }

    @ApiOperation("登录接口")
    @PostMapping("/login")
    @ApiImplicitParam(name = "loginReqVo",value = "用户登录信息",type = "body")
    public R<LoginRespVo> login(@RequestBody LoginReqVo loginReqVo) {
        return sysUserService.login(loginReqVo);

    }

    @GetMapping("/captcha")
    public R<Map<String, String>> getCaptcha() {
        return sysUserService.getCaptcha();
    }

}
